import { filterObj } from '@/utils/util'
import { deleteAction, downFile, getAction } from '@/api/manage'
import Vue from 'vue'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import JEllipsis from '@/components/jeecg/JEllipsis'
import { listCustomForm } from '@/api/form'

export const flowableMixin = {
  components: {
    JEllipsis,
  },
  data() {
    return {
      //token header
      //tokenHeader: {'X-Access-Token': Vue.ls.get(ACCESS_TOKEN)},
      customformList: [],
      formQueryParams: {
        pageNum: 1,
        pageSize: 1000,
      },
    }
  },
  created() {
    console.log('----------------------')
    this.ListCustomForm()
  },
  computed: {
    /*todo 所有的流程表单，组件化注册，在此维护*/
    allFormComponent: function () {
      return this.customformList
      // return [
      //     {
      //       text:'合同评审说明',
      //       routeName:'@/views/flowable/demo/modules/BussContractReviewDesForm',
      //       component:() => import(`@/views/flowable/demo/modules/BussContractReviewDesForm`),
      //       businessTable:'contract_review_des'
      //     },
      //   {
      //     text:'单表示例',
      //     routeName:'@/views/business/contract/modules/BussContractReviewDesForm',
      //     component:() => import(`@/views/business/contract/modules/BussContractReviewDesForm`),
      //     businessTable:'test_demo'
      //   },
      //     {
      //       text:'主子表示例',
      //       routeName:'@/views/flowable/demo/modules/CesOrderMainForm',
      //       component:() => import(`@/views/flowable/demo/modules/CesOrderMainForm`),
      //       businessTable:'ces_order_main'
      //     },
      //   {
      //     text:'入库通知单',
      //     routeName:'@/views/business/storehouse/modules/BussStorageNoticeForm',
      //     component:() => import(`@/views/business/storehouse/modules/BussStorageNoticeForm`),
      //     businessTable:'buss_storage_notice'
      //   },
      //   {
      //     text:'合同评审',
      //     routeName:'@/views/business/review/modules/BussContractRequirementReviewForm',
      //     component:() => import(`@/views/business/review/modules/BussContractRequirementReviewForm`),
      //     businessTable:'buss_contract_requirement_review'
      //   },
      // ]
    },
  },
  methods: {
    /*StringToComponent (str) {
      return function (resolve) {
        require([`${str}.vue`], resolve)
      }
    },
    replacer(key, value) {
      if ( key === "component") {
        console.log("key-value=",key,value);
        return StringToComponent (value);
      }
      return value;
    },*/
    /** 挂载自定义业务表单列表 */
   async ListCustomForm() {
      // console.log('flowableMixin ListCustomForm')
      // listCustomForm(this.formQueryParams).then((res) => {
      //   console.log('flowableMixin res')
      //   console.log('res.result.records', res.result.records)

      //   this.customformList = JSON.stringify(res.result.records, this.replacer)

      //   console.log('this.customformList =', this.customformList)
      // })
      //240909改成宁波阿成代码
      let that = this;
      listCustomForm(this.formQueryParams).then(res => {
        let  cfList = res.result.records;
        console.log('----------------------')
        cfList.forEach((item, index) => {

          let cms = {
              text:item.flowName,
              routeName:item.routeName,
              component: (resolve) => require([`@/views/${item.routeName}`], resolve), 
              //businessTable:'wf_demo'
          }
          that.customformList.push(cms);
        })
        console.log('+++++++++++++++++++++')
      })
    },
    getFormComponent(routeName) {
      return _.find(this.allFormComponent, { routeName: routeName }) || {}
    },

    handleTableChange(pagination, filters, sorter) {
      //分页、排序、筛选变化时触发
      //TODO 筛选
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field
        this.isorter.order = 'ascend' == sorter.order ? 'asc' : 'desc'
      }
      this.ipagination = pagination
      // this.loadData();
    },
    millsToTime(mills) {
      if (!mills) {
        return ''
      }
      let s = mills / 1000
      if (s < 60) {
        return s.toFixed(0) + ' 秒'
      }
      let m = s / 60
      if (m < 60) {
        return m.toFixed(0) + ' 分钟'
      }
      let h = m / 60
      if (h < 24) {
        return h.toFixed(0) + ' 小时'
      }
      let d = h / 24
      if (d < 30) {
        return d.toFixed(0) + ' 天'
      }
      let month = d / 30
      if (month < 12) {
        return month.toFixed(0) + ' 个月'
      }
      let year = month / 12
      return year.toFixed(0) + ' 年'
    },
  },
}
